#pragma once
#include <windows.h>

class Lock
{
public:
    Lock()
    {
        InitializeCriticalSection(&cs_);
    }

    ~Lock()
    {
        DeleteCriticalSection(&cs_);
    }

    void Acquire()
    {
        EnterCriticalSection(&cs_);
    }

    void Release()
    {
        LeaveCriticalSection(&cs_);
    }

private:
    CRITICAL_SECTION cs_;
};

class AutoLock
{
public:
    AutoLock(Lock& lock) : lock_(lock)
    {
        lock_.Acquire();
    }

    ~AutoLock()
    {
        lock_.Release();
    }
private:
    Lock& lock_;
};